﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace MetaHeuristics.Aco
{
    public class AcsLocalPheromoneUpdater  : BaseLocalPheromoneUpdater
    {
        private float xi = 0.5f;
        private float beta = 1;
        private float tau0 = 1;

        public float Xi
        {
            get
            {
                return this.xi;
            }
            set
            {
                this.xi = Math.Max(0, Math.Min(1, value));
            }
        }

        public float Beta
        {
            get
            {
                return this.beta;
            }
            set
            {
                this.beta = value;
            }
        }

        public float Tau0
        {
            get
            {
                return this.tau0;
            }
            set
            {
                this.tau0 = value;
            }
        }

        public override void Update(Ant ant)
        {
            int h = ant.Tours[ant.Tours.Count - 2];
            int l = ant.Tours[ant.Tours.Count - 1];

            float pheromone = (1 - this.xi) * this.Aco.Pheromones[h, l] + this.xi * this.tau0;
            this.Aco.Pheromones[h, l] = pheromone;
            this.Aco.ChoiceInfos[h, l] = (float)(pheromone * Math.Pow(1 / this.Aco.Distances[h, l], this.beta));
        }
    }
}
